#include <QDebug>
#include <QPainter>
#include "TrMdGridBase.h"
#include "include/TrGlobal.h"

CTrMdGridBase::CTrMdGridBase(QWidget *parent) : QWidget(parent)
{


    if(parent) resize(parent->size());

//    QPalette palette(this->palette());
//    palette.setColor(QPalette::Background, TrColor_Black);
//    this->setPalette(palette);
}

void CTrMdGridBase::changeEvent(QEvent* event)
{
    Q_UNUSED(event);
    updateWidgetSize();
}

void CTrMdGridBase::resizeEvent(QResizeEvent *event)
{
    Q_UNUSED(event);
    updateWidgetSize();
}

void CTrMdGridBase::updateWidgetSize()
{
    iWidth = size().width();
    iHight = size().height();
    iBotHight = iHight >= 700 ? 200 : 100;
    m_SizeOne.setWidth(iWidth - iLeftWidth - iRightWidth);
    m_SizeOne.setHeight(iHight - iBotHight - iTopHight);
}

QSize CTrMdGridBase::getBlockSize()
{
    return m_SizeOne;
}

void CTrMdGridBase::SetInstrument(QString Instrument)
{
    InstrumentID = Instrument;
}

void CTrMdGridBase::drawBaseLine(QPainter* painter)
{
    QPen pen;
    pen.setColor(coRed);
    painter->setPen(pen);

    // top
    painter->drawLine(0, iTopHight, iWidth, iTopHight);
    // left
    painter->drawLine(iRightWidth, iTopHight, iRightWidth, iHight);
    // right
    painter->drawLine(iWidth - iRightWidth, iTopHight, iWidth - iRightWidth, iHight);
    // bottom
    painter->drawLine(0, iHight - iBotHight, iWidth, iHight - iBotHight);

    int h = m_SizeOne.height() / 4;
    // middle horizontal line
    painter->drawLine(iLeftWidth, h*2 + iTopHight, m_SizeOne.width() + iLeftWidth, h*2 + iTopHight);

    pen.setColor(coRedBlk);
    pen.setStyle(Qt::DashLine);
    painter->setPen(pen);
    // horizontal line
    painter->drawLine(iLeftWidth, h + iTopHight, m_SizeOne.width() + iLeftWidth, h + iTopHight);
    painter->drawLine(iLeftWidth, h*3 + iTopHight, m_SizeOne.width() + iLeftWidth, h*3 + iTopHight);

    pen.setColor(Qt::white);
    painter->setPen(pen);
    painter->drawText(10, 19, InstrumentID);

//    if(m_maxPrice != 0.00 && m_minPrice != 0.00)
//    {
//        pen.setColor(coGray);
//        painter->setPen(pen);
//        painter->drawText(10, 43, QString::number(m_maxPrice));
//        painter->drawText(10, (iHight - iBotHight) / 2 + 17, QString::number(m_maxPrice - (m_maxPrice - m_minPrice) / 2));
//        painter->drawText(10, iHight - iBotHight - 5, QString::number(m_minPrice));
//    }

}
